/*
	This file is part of the JKTest
    Copyright (C) 2008 Royce Y. Feng <ryfeng@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package JKSysInfo;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import java.awt.GridLayout;
import java.util.Timer;
import java.util.TimerTask;

/**
 * 
 * The class that handles all GUI functions of the System Information stage
 * 
 * @author Royce Feng
 */

public class JKSysInfoGUI extends JPanel {

    private JPanel panel1 = new JPanel();
    private JPanel panel2 = new JPanel();
    private Timer sysInfoTimer = new Timer();
    
    private SysInfoClass sysInfo = new SysInfoClass();
    
    private JLabel uName = new JLabel();
    private JLabel cName = new JLabel();
    private JLabel cOSArch = new JLabel();
    private JLabel cOSName = new JLabel();
    private JLabel cOSVersion = new JLabel();
    private JLabel IPAddress = new JLabel();
    private JLabel numberOfProcessors = new JLabel();
    
    /**
     * 
     * Main constructor that creates the GUI and sets a timer to retrieve 
     * and update the System Information
     * 
     */
    public JKSysInfoGUI() {
        super(new GridLayout(1,2));
        sysInfoTimer.scheduleAtFixedRate(new SysInfoLoad(), 0, 10000);
        this.setBorder(BorderFactory.createTitledBorder("System Information"));
        panel1.setLayout(new BoxLayout(panel1,BoxLayout.Y_AXIS));
        panel2.setLayout(new BoxLayout(panel2,BoxLayout.Y_AXIS));
        panel1.add(new JLabel("User Name: "));
        panel1.add(new JLabel("Name: "));
        panel1.add(new JLabel("OS Arch: "));
        panel1.add(new JLabel("OS Name: "));
        panel1.add(new JLabel("OS Version: "));
        panel1.add(new JLabel("Local IP: "));
        panel1.add(new JLabel("Processors: "));
        panel2.add(uName);
        panel2.add(cName);
        panel2.add(cOSArch);
        panel2.add(cOSName);
        panel2.add(cOSVersion);
        panel2.add(IPAddress);
        panel2.add(numberOfProcessors);
        this.add(panel1);
        this.add(panel2);
    }
    
    /**
     * 
     * Class that is used to retrieve the System Information and update the
     * GUI. This is used by Timer.
     * 
     */
    private class SysInfoLoad extends TimerTask {
        public void run() {
            sysInfo.run();
            uName.setText(sysInfo.getuName());
            cName.setText(sysInfo.getcName());
            cOSArch.setText(sysInfo.getcOSArch());
            cOSName.setText(sysInfo.getcOSName());
            cOSVersion.setText(sysInfo.getcOSVersion());
            IPAddress.setText(sysInfo.getIPAddress());
            numberOfProcessors.setText(sysInfo.getnumberOfProcessors());
        }
    }
    
}
